﻿Public Class frmCJQuery
    Private Sub frmCJQuery_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim icount As Integer
        cboWhere.Items.Clear()
        cboWhere.Items.Add("学生姓名")
        cboWhere.Items.Add("课程名称")
        cboWhere.SelectedIndex = 0
        '初始化网格信息
        txtSQL = "SELECT 学生.学号,学生.姓名,课程.课程名称,课程.课程类别,选课.成绩 FROM 课程 INNER JOIN 选课 ON 课程.课程编号 = 选课.课程编号 INNER JOIN 学生 ON 选课.学号 = 学生.学号"
        icount = ExecuteSQL(txtSQL, ErrorMsg)
        DataGridView1.DataSource = DBSet.Tables.Item(0)
    End Sub
    '查询
    Private Sub cmdQuery_Click(sender As Object, e As EventArgs) Handles cmdQuery.Click
        If Trim(txtWord.Text) = "" Then
            MsgBox("请输入检索词")
            Exit Sub
        End If
        txtSQL = "SELECT 学生.学号,学生.姓名,课程.课程名称,课程.课程类别,选课.成绩"
        txtSQL = txtSQL & " FROM 课程 INNER JOIN"
        txtSQL = txtSQL & " 选课 ON 课程.课程编号 = 选课.课程编号 INNER JOIN"
        txtSQL = txtSQL & " 学生 ON 选课.学号 = 学生.学号"

        If cboWhere.Text = "学生姓名" Then
            txtSQL = txtSQL & "WHERE 学生.姓名'" & Trim(txtWord.Text) & "'"
        End If
        If cboWhere.Text = "课程名称" Then
            txtSQL = txtSQL & "WHERE 课程.课程名称 like '% " & Trim(txtWord.Text) & "%'"
        End If
        Dim icount As Integer
        icount = ExecuteSQL(txtSQL, ErrorMsg)
        DataGridView1.DataSource = DBSet.Tables.Item(0)

    End Sub

    Private Sub cmdExit_Click(sender As Object, e As EventArgs) Handles cmdExit.Click
        Me.Close()
    End Sub
End Class